Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Node / AutumnSpark1226 / nomadForum.git / files / test / prepare_test_database.py

Displaying Raw • Download


test/prepare_test_database.py main (dac94b89) Text, 3.04 KB

T8b949e#!/usr/bin/env python3


T8b949e# nomadForum - a forum on the NomadNetwork
T8b949e# Copyright (C) 2023-2026 AutumnSpark1226
T8b949e#
T8b949e# This program is free software: you can redistribute it and/or modify
T8b949e# it under the terms of the GNU General Public License as published by
T8b949e# the Free Software Foundation, either version 3 of the License, or
T8b949e# (at your option) any later version.
T8b949e#
T8b949e# This program is distributed in the hope that it will be useful,
T8b949e# but WITHOUT ANY WARRANTY; without even the implied warranty of
T8b949e# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
T8b949e# GNU General Public License for more details.
T8b949e#
T8b949e# You should have received a copy of the GNU General Public License
T8b949e# along with this program. If not, see <https://www.gnu.org/licenses/>.

Tff7b72import T7ee787os
Tff7b72import T7ee787sys

Tff7b72from T7ee787argon2 Tff7b72import Te6edf3PasswordHasher

Te6edf3sysTff7b72.Td2a8ffpathTff7b72.Td2a8ffextendTb4b4b4(Tb4b4b4[Te6edf3osTff7b72.Td2a8ffpathTff7b72.Td2a8ffabspathTb4b4b4(Te6edf3osTff7b72.Td2a8ffpathTff7b72.Td2a8ffjoinTb4b4b4(Te6edf3osTff7b72.Td2a8ffpathTff7b72.Td2a8ffdirnameTb4b4b4(Tff7b72__file__Tb4b4b4)Tb4b4b4, Te6edf3osTff7b72.Td2a8ffpardirTb4b4b4)Tb4b4b4)Tb4b4b4]Tb4b4b4)
Tff7b72import T7ee787main

Te6edf3mainTff7b72.Td2a8ffsetup_dbTb4b4b4(Tb4b4b4)
T8b949e# add an admin account (username: 'ADMIN' password: '12345678')
Te6edf3hashed_password Tff7b72= Te6edf3PasswordHasherTb4b4b4(Tb4b4b4)Tff7b72.Td2a8ffhashTb4b4b4(Ta5d6ff"Ta5d6ff12345678Ta5d6ff"Tb4b4b4)
Te6edf3prepared_password Tff7b72= Te6edf3mainTff7b72.Td2a8ffencryptTb4b4b4(Te6edf3hashed_passwordTb4b4b4)
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6fffTa5d6ff"Ta5d6ffINSERT INTO users (username, password, display_name, about, default_styling) VALUES (Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Tffd700{Te6edf3prepared_passwordTffd700}Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffNoneTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffNoneTa5d6ff'Ta5d6ff)Ta5d6ff"
Tb4b4b4)
T8b949e# add a user account (username: 'user' password: 'abcdefghi')
Te6edf3hashed_password Tff7b72= Te6edf3PasswordHasherTb4b4b4(Tb4b4b4)Tff7b72.Td2a8ffhashTb4b4b4(Ta5d6ff"Ta5d6ffabcdefghiTa5d6ff"Tb4b4b4)
Te6edf3prepared_password Tff7b72= Te6edf3mainTff7b72.Td2a8ffencryptTb4b4b4(Te6edf3hashed_passwordTb4b4b4)
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6fffTa5d6ff"Ta5d6ffINSERT INTO users (username, password, display_name, about, default_styling) VALUES (Ta5d6ff'Ta5d6ffuserTa5d6ff'Ta5d6ff, Ta5d6ff'Tffd700{Te6edf3prepared_passwordTffd700}Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffuserTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffNoneTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffNoneTa5d6ff'Ta5d6ff)Ta5d6ff"
Tb4b4b4)
T8b949e# add some posts and comments
T8b949e# post 0
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6ff"Ta5d6ffINSERT INTO posts (post_id, username, title, content, created, changed, last_action) VALUES (Ta5d6ff'Ta5d6ff00000000-0000-0000-0000-000000000001Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffTest postTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffThis is a test post.Ta5d6ff'Ta5d6ff, unixepoch(), unixepoch(), unixepoch())Ta5d6ff"
Tb4b4b4)
T8b949e# comment 0
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6ff"Ta5d6ffINSERT INTO comments (comment_id, post_id, parent, username, content, created, changed) VALUES (Ta5d6ff'Ta5d6ff00000000-0000-0000-0001-000000000000Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ff00000000-0000-0000-0000-000000000001Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffpostTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffThis is test comment 0Ta5d6ff'Ta5d6ff, unixepoch(), unixepoch())Ta5d6ff"
Tb4b4b4)
T8b949e# comment 1
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6ff"Ta5d6ffINSERT INTO comments (comment_id, post_id, parent, username, content, created, changed) VALUES (Ta5d6ff'Ta5d6ff00000000-0000-0000-0002-000000000000Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ff00000000-0000-0000-0000-000000000001Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ff00000000-0000-0000-0001-000000000000Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffThis is test comment 1Ta5d6ff'Ta5d6ff, unixepoch(), unixepoch())Ta5d6ff"
Tb4b4b4)
T8b949e# comment 2
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6ff"Ta5d6ffINSERT INTO comments (comment_id, post_id, parent, username, content, created, changed) VALUES (Ta5d6ff'Ta5d6ff00000000-0000-0000-0003-000000000000Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ff00000000-0000-0000-0000-000000000001Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffpostTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffThis is test comment 2Ta5d6ff'Ta5d6ff, unixepoch(), unixepoch())Ta5d6ff"
Tb4b4b4)
T8b949e# post 1
Te6edf3mainTff7b72.Td2a8ffexecute_sqlTb4b4b4(
Ta5d6ff"Ta5d6ffINSERT INTO posts (post_id, username, title, content, created, changed, last_action) VALUES (Ta5d6ff'Ta5d6ff00000000-0000-0000-0000-000000000002Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffADMINTa5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffTest post 2Ta5d6ff'Ta5d6ff, Ta5d6ff'Ta5d6ffThis is another test post.Ta5d6ff'Ta5d6ff, unixepoch(), unixepoch(), unixepoch())Ta5d6ff"
Tb4b4b4)
Te6edf3mainTff7b72.Td2a8ffclose_databaseTb4b4b4(Tb4b4b4)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────